export function configsTodefaultValue(configs = {}) {
  const obj = {}
  Object.entries(configs).forEach(([key, cfgs]) => {
    const { type = 'object', options, defaultValue } = cfgs
    const value = type === 'object' ? configsTodefaultValue(options) : defaultValue
    obj[key] = value
  })
  return obj
}

export function widgetsToGroupWidgets(widgets = {}) {
  const groupWidgets = {}
  Object.entries(widgets).forEach(([key, widget]) => {
    const { label, icon, group, Chart } = widget
    const widgetInfo = {
      label,
      icon,
      type: Chart ? 'chart' : 'widget'
    }
    if (group) {
      if (!groupWidgets[group]) {
        groupWidgets[group] = {
          ...widgetInfo,
          children: {}
        }
      }
      groupWidgets[group].children[key] = widgetInfo
    } else {
      groupWidgets[key] = widgetInfo
    }
  })
  return groupWidgets
}
